<?php
//Function get location

class ListPostCode
{
	var $listLat = array();
	var $listLog = array();
	var $tamp = 0;
	var $mytotal =0;
	var $caboffice_id;
	var $car_id;
	var $milage;
	var $fare;
	var $timestap;
	var $totalPrice=0;
function calculation_Price()
{
	// $sql_info = "SELECT  * FROM caboffice_milage order by DESC";
	// $result = mysql_query($sql_info);
	$Totals = $this->getTotal();
	// while($row = mysql_fetch_row($result))
	// {
					// $row['milage']>$Totals;
					
		// if($row['car_id'] == 1)
		// {
			if(1<= $Totals && $Totals<=10) return ($Totals*6);
			if(10<$Totals && $Totals<=30) return ($Totals*4);
			if(30<$Totals && $Totals<=100) return ($Totals*3);
			if($Totals>100) return ($Totals*2);
		// }
		// if($row['car_id'] == 2)
		// {
			// if(1<= $Totals && $Totals<=10) return ($Totals*7);
			// if(10<$Totals && $Totals<=30) return ($Totals*5);
			// if(30<$Totals && $Totals<=100) return ($Totals*4);
			// if($Totals>100) return ($Totals*3);
		// }	
	// }q
}
// function 
function connect_db() {
		
		$conn_str = mysql_connect('localhost', 'root', 'root');
		mysql_select_db('cabee'); // if there are problems with the tablenames inside the config file use this row 
	}
	
 function postOri_des($origin, $destination)
{
	// $postcode = $_REQUEST['postcode'];
	// $url = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.$postcode.'&sensor=false';
	// $url = 'http://www.uk-postcodes.com/distance.php?lat=57.148235&lng=-2.096648&distance=1&format=xml';
	// $url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='.$origin.'&destination='.$destination.'&waypoints=&sensor=false';
	// $url = 'http://maps.googleapis.com/maps/api/directions/xml?origin=Toledo&destination=Madrid&waypoints=&sensor=false';
	// $url = 'http://maps.googleapis.com/maps/api/directions/xml?origin=Scoresby&destination=Melborne&sensor=false';
	// $url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='.$origin.'&destination='.$destination.'&sensor=false';
	$url = "http://maps.googleapis.com/maps/api/directions/xml?origin=$origin\&destination=$destination\&sensor=false";
	$parsedXML = simplexml_load_file($url);
		
		if($parsedXML->status != "OK") {
		echo "There has been a problem: " . $parsedXML->status;
		// return;
		}
		foreach($parsedXML->route->leg->step as $step) {
			$this->listLat[tamp] = $step->start_location->lat;
			$this->listLog[tamp] = $step->start_location->lng;
			$this->tamp++;
			$this->mytotal+=$step->duration->value;
		}
		$this->mytotal = $this->mytotal/1000;
	}	
	function getListLat()
	{
		return $this->listLat;
	}
	//return array list longtitude
	function getListLog()
	{
		return $this->listLog;
	}
	//return km distance between two points
	function getTotal()
	{
		return $this->mytotal;
	}
// function computeTotalDistance(result) {
  // var $total = 0;
  // var myroute = result.routes[0];
  // for (i = 0; i < myroute.legs.length; i++) {
    // total += myroute.legs[i].distance.value;
  // }
  // total = total / 1000.
  // document.getElementById("total").innerHTML = total + " km";
// }
	// $myAddress = array();
	// foreach($parsedXML->result->address_component as $component) {
	// if(is_array($component->type)) $type = (string)$component->type[0];
	// else $type = (string)$component->type;

	// $myAddress[$type] = (string)$component->long_name;
	// }
	// header('Content-Type: application/json');
	// echo json_encode($myAddress);
		function getInfoLocal($param) // GEt info from local ..$param is poscode
	{
		$sql = "SELECT street, county,town FROM local where postcode='".$param."'";
		$r = mysql_query($sql);
		if (!$r) {
			echo $sql;
			$this->last_error = mysql_error();
         return false;
		} else {
			 $row = mysql_fetch_row($r);
			{
			// return true;
			 $result = array($row[0],$row[1],$param);
			foreach ($result as $value)
			echo $value."|";
			 // $this->street = $row[0];
			 // $this->country = $row[1];
			 // echo  "street loddcal: ". $this->street;
			 // echo  json_encode($result );
			  // $this->insetgeo_gpc();
			 // mysql_free_result($r);
			// return $result;    
			}
		}      
	}
}
?>
